/**
 * Created by chengcong on 2017/11/22.
 */
$('.return').on('click',function (e) {
    window.history.back();
});
var msg=window.sessionStorage['user_msg'];
msg=JSON.parse(msg);
$(function() {
    socket.emit('login',{
        token:msg.token,
        username :msg.username,
        openid  :null,
        sex : 0,
        marking :1,//1pc  2wx  3app  Number
        userrole :msg.userrole//登陆角色 (医生(1)，用户(2)，助理(3)，药师(4),匿名用户(5))
    });
    var arr=location.search.split("=");
    $.ajax({
        url: url + '/server/mes',
        type: 'post',
        data: {
            _id: arr[1]
        },
        headers: {
            'Authorization': 'Bearer ' + msg.token
        },
        success: function (data) {
            console.log(data);
            var detailmsg = '';
            if (data.code == 200) {
                detailmsg = data.data;
            } else {
                alert(data.mes)
            }
            $('.serresult').text(detailmsg.serverSuggest);
            $('.assresult').text(detailmsg.systemResult);
            $('.title').text(detailmsg.information.classify.join('')+'采集单')
            $('.question').html('');
            for(var i=0;i<detailmsg.information.subject.length;i++){
                $('.question').append('<p>'+(i+1)+'.'+detailmsg.information.subject[i].subjectName+':</p>')
                if(detailmsg.information.subject[i].type==1){
                    for(var j=0;j<detailmsg.information.subject[i].select.length;j++){
                    	console.log(detailmsg.information.subject[i].select[j].checked)
                        if(detailmsg.information.subject[i].select[j].checked==true){
                            $('.question').append('<span><input type="radio" name="radio'+i+'" checked="checked" disabled>'+detailmsg.information.subject[i].select[j].selectName+'</span>')
                        }else {
                            $('.question').append('<span><input type="radio" name="radio'+i+'" disabled>'+detailmsg.information.subject[i].select[j].selectName+'</span>')
                        }
                    }
                }
                if(detailmsg.information.subject[i].type==2){
                    for(var j=0;j<detailmsg.information.subject[i].select.length;j++){
                        if(detailmsg.information.subject[i].select[j].checked==true){
                            $('.question').append('<span><input type="checkbox" checked="checked" disabled>'+detailmsg.information.subject[i].select[j].selectName+'</span>')
                        }else {
                            $('.question').append('<span><input type="checkbox" disabled>'+detailmsg.information.subject[i].select[j].selectName+'</span>')
                        }

                    }
                }
                if(detailmsg.information.subject[i].type==3){
                    $('.question').append('<p>'+detailmsg.information.subject[i].describe+'</p>')
                }
                if(detailmsg.information.subject[i].type==4){
                    for(var j=0;j<detailmsg.information.subject[i].img.length;j++){
                        $('.question').append('<img src="'+detailmsg.information.subject[i].img[j]+'" width="100px" height="100px">')
                    }
                }

            }
        }
    })
})
//审核不通过通知消息
socket.on("notthrough_msg",function(data){
    console.log(data.msg+data._id[0]);
    var bottom=-200;
    var timer=setInterval(function () {
        bottom+=4;
        window.top.document.getElementById('msgnew').style.bottom=bottom+'px';
        window.top.document.getElementsByClassName('newmsg')[0].innerHTML='审核不通过';
        if(bottom>0){
            clearInterval(timer);
        }
    },47)
    window.top.document.getElementsByClassName('unfinish')[0].innerHTML=
        parseFloat(window.top.document.getElementsByClassName('unfinish')[0].innerHTML)+1;
    window.top.document.getElementsByClassName('unfinish')[0].style.display='inline-block';
})
//撤回指派
socket.on("Undo", function(data2) {
    console.log(data2, 222)
    window.top.document.getElementsByClassName('unfinish')[0].innerHTML =
        parseFloat(window.top.document.getElementsByClassName('unfinish')[0].innerHTML) - 1;
    if(parseFloat(window.top.document.getElementsByClassName('unfinish')[0].innerHTML) > 0) {
        window.top.document.getElementsByClassName('unfinish')[0].style.display = 'inline-block';
    } else {
        window.top.document.getElementsByClassName('unfinish')[0].style.display = 'none';
    }
    alert(data2.name+"撤回指派")
})
//撤回邀请
socket.on("UndoInvite", function(data) {
    window.top.document.getElementsByClassName('invitelist')[0].innerHTML =
        parseFloat(window.top.document.getElementsByClassName('invitelist')[0].innerHTML) - 1;
    if(parseFloat(window.top.document.getElementsByClassName('invitelist')[0].innerHTML) > 0) {
        window.top.document.getElementsByClassName('invitelist')[0].style.display = 'inline-block';
    } else {
        window.top.document.getElementsByClassName('invitelist')[0].style.display = 'none';
    }
});